package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.dbo.StatPageInfo;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.common.util.Page;
import com.mo2323.service.merchant.IMemberShipCardService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author xjw
 * @date 2019/1/23 - 17:48
 */
@Controller
@RequestMapping("/memberShipCard")
public class MemberShipCardController extends BaseController {

    @Reference
    private IMemberShipCardService memberShipCardService;


    @RequestMapping(value = "/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getMemberShipCardList(@RequestParam int vid, String cardName,
                                            @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                            @RequestParam(value = "rows", defaultValue = "10", required = false) int rows) {
        try {
            Page pageDefine = new Page();
            pageDefine.setPage(page);
            pageDefine.setRows(rows);

            StatPageInfo<Map<String, Object>> pageInfo = memberShipCardService.getMemberShipCardList(vid, cardName, pageDefine);
            return AjaxObject.ok().put("data", pageInfo);
        } catch (Exception e) {
            logger.error("getMemberShipCardList Exception：", e);
            return AjaxObject.error("getMemberShipCardList Exception：" + e.getMessage());
        }
    }

    @RequestMapping(value = "/memberShipCardRecharge", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject memberShipCardRecharge(@RequestParam Integer vid, @RequestParam Integer cid, @RequestParam Double payMoney, @RequestParam Double money) {
        try {
            memberShipCardService.memberShipCardRecharge(vid, cid, payMoney, money);
            return AjaxObject.ok().data("充值成功!");
        } catch (Exception e) {
            logger.error("memberShipCardRecharge Exception：", e);
            return AjaxObject.error("memberShipCardRecharge Exception：" + e.getMessage());
        }
    }


}
